<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省份" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市" prop="citycode">
        <el-input
          v-model="queryParams.citycode"
          placeholder="请输入市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="县" prop="countycode">
        <el-input
          v-model="queryParams.countycode"
          placeholder="请输入县"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="协会选择" prop="association">
        <el-input
          v-model="queryParams.association"
          placeholder="请输入协会选择"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="艺术家类型" prop="associationType">
        <el-input
          v-model="queryParams.associationType"
          placeholder="请输入艺术家类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证书" prop="certificate">
        <el-input
          v-model="queryParams.certificate"
          placeholder="请输入证书"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证书编号" prop="certificateNumber">
        <el-input
          v-model="queryParams.certificateNumber"
          placeholder="请输入证书编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会费开始时间" prop="sxpiryCreate">
        <el-date-picker clearable
          v-model="queryParams.sxpiryCreate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择会费开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="会费到期时间" prop="sxpiryDate">
        <el-date-picker clearable
          v-model="queryParams.sxpiryDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择会费到期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="会费状态" prop="membershipTatus">
        <el-input
          v-model="queryParams.membershipTatus"
          placeholder="请输入会费状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销量" prop="sales">
        <el-input
          v-model="queryParams.sales"
          placeholder="请输入销量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="第几届" prop="several">
        <el-input
          v-model="queryParams.several"
          placeholder="请输入第几届"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="书法家的级别" prop="level">
        <el-input
          v-model="queryParams.level"
          placeholder="请输入书法家的级别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="condition">
        <el-input
          v-model="queryParams.condition"
          placeholder="请输入状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:information:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:information:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:information:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:information:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="informationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="个人信息id" align="center" prop="id" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="头像" align="center" prop="avatar" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.avatar" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="简介" align="center" prop="profile" />
      <el-table-column label="省份" align="center" prop="province" />
      <el-table-column label="市" align="center" prop="citycode" />
      <el-table-column label="县" align="center" prop="countycode" />
      <el-table-column label="协会选择" align="center" prop="association" />
      <el-table-column label="艺术家类型" align="center" prop="associationType" />
      <el-table-column label="证书" align="center" prop="certificate" />
      <el-table-column label="证书编号" align="center" prop="certificateNumber" />
      <el-table-column label="会费开始时间" align="center" prop="sxpiryCreate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sxpiryCreate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会费到期时间" align="center" prop="sxpiryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sxpiryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会费状态" align="center" prop="membershipTatus" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="销量" align="center" prop="sales" />
      <el-table-column label="第几届" align="center" prop="several" />
      <el-table-column label="书法家的级别" align="center" prop="level" />
      <el-table-column label="状态" align="center" prop="condition" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:information:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:information:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改个人信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="头像" prop="avatar">
          <image-upload v-model="form.avatar"/>
        </el-form-item>
        <el-form-item label="简介">
          <editor v-model="form.profile" :min-height="192"/>
        </el-form-item>
        <el-form-item label="省份" prop="province">
          <el-input v-model="form.province" placeholder="请输入省份" />
        </el-form-item>
        <el-form-item label="市" prop="citycode">
          <el-input v-model="form.citycode" placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="县" prop="countycode">
          <el-input v-model="form.countycode" placeholder="请输入县" />
        </el-form-item>
        <el-form-item label="协会选择" prop="association">
          <el-input v-model="form.association" placeholder="请输入协会选择" />
        </el-form-item>
        <el-form-item label="艺术家类型" prop="associationType">
          <el-input v-model="form.associationType" placeholder="请输入艺术家类型" />
        </el-form-item>
        <el-form-item label="证书" prop="certificate">
          <el-input v-model="form.certificate" placeholder="请输入证书" />
        </el-form-item>
        <el-form-item label="证书编号" prop="certificateNumber">
          <el-input v-model="form.certificateNumber" placeholder="请输入证书编号" />
        </el-form-item>
        <el-form-item label="会费开始时间" prop="sxpiryCreate">
          <el-date-picker clearable
            v-model="form.sxpiryCreate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择会费开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会费到期时间" prop="sxpiryDate">
          <el-date-picker clearable
            v-model="form.sxpiryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择会费到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会费状态" prop="membershipTatus">
          <el-input v-model="form.membershipTatus" placeholder="请输入会费状态" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="销量" prop="sales">
          <el-input v-model="form.sales" placeholder="请输入销量" />
        </el-form-item>
        <el-form-item label="第几届" prop="several">
          <el-input v-model="form.several" placeholder="请输入第几届" />
        </el-form-item>
        <el-form-item label="书法家的级别" prop="level">
          <el-input v-model="form.level" placeholder="请输入书法家的级别" />
        </el-form-item>
        <el-form-item label="状态" prop="condition">
          <el-input v-model="form.condition" placeholder="请输入状态" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInformation, getInformation, delInformation, addInformation, updateInformation } from "@/api/system/information";

export default {
  name: "Information",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 个人信息表格数据
      informationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        name: null,
        avatar: null,
        profile: null,
        province: null,
        citycode: null,
        countycode: null,
        association: null,
        associationType: null,
        certificate: null,
        certificateNumber: null,
        sxpiryCreate: null,
        sxpiryDate: null,
        membershipTatus: null,
        sales: null,
        several: null,
        level: null,
        condition: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询个人信息列表 */
    getList() {
      this.loading = true;
      listInformation(this.queryParams).then(response => {
        this.informationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        name: null,
        avatar: null,
        profile: null,
        province: null,
        citycode: null,
        countycode: null,
        association: null,
        associationType: null,
        certificate: null,
        certificateNumber: null,
        sxpiryCreate: null,
        sxpiryDate: null,
        membershipTatus: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        sales: null,
        several: null,
        level: null,
        condition: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加个人信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInformation(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改个人信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInformation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除个人信息编号为"' + ids + '"的数据项？').then(function() {
        return delInformation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/information/export', {
        ...this.queryParams
      }, `information_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
